﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
    function onVehicleModelChange(e) {
        var nextDropDownList;
        if (e.currentTarget.id == "vehicleManufactureDropDownList") {
            nextDropDownList = $('#vehicleModelDropDownList').data('tDropDownList');
        } else if (e.currentTarget.id == "vehicleModelDropDownList") {
            nextDropDownList = $('#vehicleEngineTypeDropDownList').data('tDropDownList');
        } else if (e.currentTarget.id == "vehicleEngineTypeDropDownList") {
            nextDropDownList = $('#vehicleModelYearDropDownList').data('tDropDownList');
        } else if (e.currentTarget.id == "vehicleModelYearDropDownList") {
            var vehicleModelTxt = $('#VehicleModel');
            vehicleModelTxt[0].value = $('#vehicleManufactureDropDownList').data('tDropDownList').value() + '-' +
                                          $('#vehicleModelDropDownList').data('tDropDownList').value() + '-' +
                                          $('#vehicleEngineTypeDropDownList').data('tDropDownList').value()+'-'+
                                          $('#vehicleModelYearDropDownList').data('tDropDownList').value();
            var vehicleTypeIDTxt = $('#VehicleTypeID');
            vehicleTypeIDTxt[0].value = $('#vehicleModelYearDropDownList').data('tDropDownList').value();
            return;
        }
        nextDropDownList.value("");
        nextDropDownList.reload("");
    }
    function onVehicleModelDataBinding(e) {
        var lastDropDownList;
        var inputString;
        if (e.currentTarget.id == "vehicleModelDropDownList") {
            inputString = $('#vehicleManufactureDropDownList').data('tDropDownList').value();

        } else if (e.currentTarget.id == "vehicleEngineTypeDropDownList") {
            inputString = $('#vehicleManufactureDropDownList').data('tDropDownList').value() + ';' +
                          $('#vehicleModelDropDownList').data('tDropDownList').value();
        } else if (e.currentTarget.id == "vehicleModelYearDropDownList") {
            inputString = $('#vehicleManufactureDropDownList').data('tDropDownList').value() + ';' +
                          $('#vehicleModelDropDownList').data('tDropDownList').value() + ';' +
                          $('#vehicleEngineTypeDropDownList').data('tDropDownList').value();
        }
        e.data = $.extend({}, e.data, { input: inputString });
    }
    

     function onCustomerSelected(e) {
            customerID = e.row.cells[0].innerHTML;
            $('#result').load('<%= Url.Action("GetCustomerDetail", "Customer")%>', "CustomerID="+customerID);
    }
    
        
</script>

<% Html.Telerik().Grid<WiseLink.RDS.Model.CustomerViewModel>()
    .Name("Customer")
    .Editable(e => e.Mode(GridEditMode.PopUp))
    .DataKeys(keys =>
    {
        keys.Add(c => c.CustomerID);
    })
    .ToolBar(commands =>
    {
        commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" });
    })
    .Columns(columns =>
    {
        columns.Bound(c => c.CustomerID).Hidden();
        columns.Bound(c => c.Name).Width(100);
        columns.Bound(c => c.PrimaryPhone).Width(200);
        columns.Bound(c => c.VehicleModel).Width(300);
        columns.Command(commands => { commands.Edit(); commands.Delete(); });
    })
    .DataBinding(dataBinding => dataBinding.Ajax()
                .Select("FirstLook", "Customer")
                .Insert("_InsertCustomerEditing", "Customer")
                .Update("_UpdateCustomerEditing", "Customer")
                .Delete("_DeleteCustomerEditing", "Customer")
                )
    .Filterable()
    .Pageable()
    .Selectable()
    .ClientEvents(events => events.OnRowSelect("onCustomerSelected"))
    .Render();
    
    
     
    %>
   
<p />
<div id="result">
</div>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
